package com.tedu.ivos.vehicle.contorller;

import com.tedu.ivos.base.response.JsonResult;
import com.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import com.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import com.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import com.tedu.ivos.vehicle.service.IVehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {

    @Autowired
    IVehicleService iVehicleService;

    @GetMapping("select")
    public JsonResult select(VehicleQuery vehicleQuery){
        log.debug("车辆查询，参数：{}",vehicleQuery);
        List<VehicleVO> list = iVehicleService.selectVehicle(vehicleQuery);
        log.debug(list.toString());
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam){
        log.debug("保存车辆，参数：{}",vehicleSaveParam);
        iVehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("delete")
    public JsonResult deleteVehicle(Long id){
        log.debug("删除车辆，参数：{}",id);
        iVehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }
    @PostMapping("unbind")
    public JsonResult unbindVehicle(Long id){
        log.debug("解绑车辆，参数：{}",id);
        iVehicleService.unbindVehicle(id);
        return JsonResult.ok();
    }
    @PostMapping("/bind/{geofenceId}/{id}")
    public JsonResult bindVehicle(@PathVariable Long geofenceId, @PathVariable Long id){
        log.debug("绑定车辆，参数：{},{}",geofenceId,id);
        iVehicleService.bindVehicle(geofenceId,id);
        return JsonResult.ok();
    }
}
